<template>
  <div class="app-container">
    <div class="searchBox">
      <el-form :inline="true">
        <el-form-item label="标题：">
          <el-input v-model="search.title" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="消息状态：">
          <el-select v-model="search.status" placeholder="请选择" clearable>
            <el-option
              v-for="item in controlData.messageStatus"
              :key="item.value"
              :label="item.key"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="searchQuery">查询</el-button>
          <el-button
            type="info"
            @click="
              search = {};
              searchQuery();
            "
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </div>

    <qm-table
      ref="qmTable"
      :data="query"
      keyProp="messageId"
      :showToolbar="false"
      :showCheckbox="false"
      :showDelete="false"
      :showEdit="false"
      :showFormFooter="true"
      :menuOptions="{
        width: 80,
        align: 'center',
      }"
      isCustomForm
    >
      <qm-table-column field="title" sortable="true">标题</qm-table-column>
      <qm-table-column
        field="status"
        sortable="true"
        :renderFunc="renderMessageStatus"
        >状态</qm-table-column
      >
      <qm-table-column
        field="createdDate"
        fieldType="datetime"
        style="width: 140px"
        >创建时间</qm-table-column
      >
      <qm-table-column field="createdUserName" style="width: 88px"
        >发送人</qm-table-column
      >
      <template v-slot:form="{ models, controlData, disabled }">
        <create
          ref="create"
          :models="models"
          :controlData="controlData"
          :disabled="disabled"
        ></create>
      </template>
    </qm-table>
  </div>
</template>

<script>
import Controller from "@/libs/framework/controller";
import Create from "./create";
export default class Instance extends Controller {
  onBeforeInit() {
    this.urls = {
      model: "/message/sysMessage/getListModel",
      query: "/message/sysMessage/queryUnreadEffectiveMessage",
      entity: "/message/sysMessage/getEntity",
    };
  }

  onBeforeSave(postModel) {
    if (!postModel.model.messageType) {
      this.vm.notifyError("请选择消息类型");
      return false;
    }
    if (!postModel.model.systemId) {
      this.vm.notifyError("请选择应用系统");
      return false;
    }
    if (!postModel.model.priority) {
      this.vm.notifyError("请选择优先级");
      return false;
    }
    if (this.$util.isArray(postModel.model.users)) {
      let vm = this.vm.$refs["qmTable"].viewModel;
      let userNames = [];

      this.$util.each(postModel.model.users, function (item1, ii) {
        let find = this.$util.find(vm.controlData.userList, (item) => {
          return item.loginId === item1;
        });
        if (find && find.userName) {
          userNames.push(find.userName);
        }
      });
      postModel.model.usersName = userNames.join(",");
      postModel.model.users = postModel.model.users.join(",");
    }
    return true;
  }

  mixin() {
    return {
      components: { Create },
      data() {
        return {};
      },
      methods: {
        renderMessageStatus(data, row, column) {
          let find = this.super.$util.find(
            this.controlData.messageStatus,
            (item) => {
              return item.value === data;
            }
          );
          return (find || {}).key;
        },
      },
     
    };
  }
}
</script>

<style scoped lang="scss">
</style>
